﻿using System;
using Tiny.Imaging.Filter.PixelLibrary;

namespace Tiny.Imaging.Filter.PointFilter
{
    public class InvertFilter : BaseFilter.BaseFilter
    {
        private readonly int[] _mapping;

        public InvertFilter(Func<int, int, int> blend = null, int opacity = 100)
            : base(blend, opacity)
        {
            _mapping = new int[256];
            for (int i = 0; i < 256; ++i)
            {
                _mapping[i] = Blend(i, 255 - i);
            }
        }

        public override int Process(Rgba rgba)
        {
            rgba.R = _mapping[rgba.R];
            rgba.G = _mapping[rgba.G];
            rgba.B = _mapping[rgba.B];

            return rgba.ToInteger();
        }
    }
}